import { Component, OnInit } from '@angular/core';
import { FormControl,FormGroup,FormArray } from "@angular/forms";

@Component({
  selector: 'app-reactive-form',
  templateUrl: './reactive-form.component.html',
  styleUrls: ['./reactive-form.component.css']
})
export class ReactiveFormComponent implements OnInit {
  //用formModel这个对象来表示整个表单的数据。
  formModel:FormGroup = new FormGroup({
    dateRange: new FormGroup({
      from: new FormControl(),
      to: new FormControl()
    }),
    emails: new FormArray([
      new FormControl(),
      new FormControl()
    ])
  })

  username: FormControl = new FormControl("aaa");//括号里表示这个的初识值。
  
  constructor() { }

  ngOnInit() {
  }

  onSubmit() {
    console.log(this.formModel.value);
  }

  addEmail() {
    let emails = this.formModel.get("emails") as FormArray;

    emails.push(new FormControl())
  }

}
